<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0; padding: 0;
        }
        .box{
            width: 250px;
            height: 270px;
            background-color: aquamarine;
            margin: 100px auto;
        }
        .box span{
            display: block;
            padding-top: 15px;
            color: #333;
            font-size: 20px;
            text-align: center;
        }
        .box form{
            margin-top: 20px;
        }
        .box form input{
            width: 150px;
            height: 20px;
            outline: none;
        }
        form  p{
            display: inline-block;
            width: 70px;
            text-align: justify;
            text-align-last: justify;
        }
        form .ul{
            margin-top: 20px;
        }
        #btn{
            display: block;
            width: 70px;
            height: 40px;
            margin: auto;
            color: #fff;
            font-size: 16px;
            background-color: #d0021b;
            border: none;
            margin-top: 50px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="box">
        <span>华为账号注册</span>
        <form action="">
            <div class="uo">
                <p>用户名：</p><input type="text" id="un">
            </div>
            <div class="ul">
                <p>密码：</p><input type="password" id="pwd">
            </div>
        </form>
        <input type="submit" name="" value="注册" id="btn">
    </div>
    <script src="./lib/ajax.js"></script>
    <script>
        var btn=document.querySelector('#btn');
        var unInp=document.querySelector('#un');
        var pwdInp=document.querySelector('#pwd')
        btn.onclick=function(){
            var username = unInp.value;
            var password = pwdInp.value;
            // 3 ajax验证数据
            getSend('./interface/register.php?un=' + username + '&pw=' + password, function (data) {
                console.log(data) //后端返回的数据
                var result = JSON.parse(data); // 把json字符串转成js对象
                if (result.code == 1) {
                    alert('注册成功，请重新登录');
                    location.href = "hhff/log.html"
                } else {
                    alert('用户名已被使用，请重新注册')
                }
            })
        }
    </script>
</body>
</html>